import csv
from concurrent import futures
import requests
import pandas as pd
import time
import tqdm
import random


def parse(self, response):
    def get_data(start_time, end_time, air="CTU"):
        url_get_data = "https://data-api.133.cn/api/v1/airport/statistics"
        params = {
            "airport": air,
            "route_type": "all",
            "start_time": start_time,
            "end_time": end_time
        }
        headers = {
            "Authorization": "bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvZGF0YS1hcGkuMTMzLmNuXC9hcGlcL3YxXC9hdXRoXC9sb2dpbiIsImlhdCI6MTY2Mjc3NDAyNiwiZXhwIjoxNjYyODYwNDI2LCJuYmYiOjE2NjI3NzQwMjYsImp0aSI6IjNsWXdhTVJlVnZaUjluakIiLCJzdWIiOjI0NTQsInBydiI6IjIzYmQ1Yzg5NDlmNjAwYWRiMzllNzAxYzQwMDg3MmRiN2E1OTc2ZjcifQ.L4wbmjyX2jNwWCN31Enz-mVlQGhMKVqkq-4R9VWBBr0",
            "Origin": "https://dast.133.cn",
            "Referer": "https://dast.133.cn/",
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36",
            "client-id": "3l2vZQl0aRhStPUE",
            "Content-Type": "application/x-www-form-urlencoded",
            "sec-ch-ua-mobile": "?0",
            "sec-ch-ua-platform": "Windows",
            "Sec-Fetch-Dest": "empty",
            "Sec-Fetch-Mode": "cors",
            "Sec-Fetch-Site": "same-site"
        }
        resp = requests.get(url=url_get_data, params=params, headers=headers)
        resp_json = resp.json()
        arr_plan = resp_json["data"]["fluctuation"]["arr_plan"]  # 计划进港
        arr_real = resp_json["data"]["fluctuation"]["arr_real"]  # 实际进港
        dep_plan = resp_json["data"]["fluctuation"]["dep_plan"]  # 计划出港
        dep_real = resp_json["data"]["fluctuation"]["dep_real"]  # 实际出港

        data_list = arr_plan + arr_real + dep_plan + dep_real
        return data_list

    # def main(da):
    #     data = get_data(start_time=da, end_time=da)
    #     dataWriter.writerow([da] + data)

    if __name__ == '__main__':
        print('hello')
